package com.ruyuan.seckilling.render.controller;

import com.ruyuan.seckilling.common.MapResult;
import com.ruyuan.seckilling.render.entity.PageTemplate;
import com.ruyuan.seckilling.render.service.PageTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author zhonghuashishan
 */
@RestController
@RequestMapping("/pageRender/pageTemplate")
public class PageTemplateController {

    @Autowired
    private PageTemplateService pageTemplateService;

    @GetMapping("/{id}")
    public PageTemplate queryById(@PathVariable("id") Long id) {
        return pageTemplateService.queryById(id);
    }

    @PostMapping
    public MapResult save(@RequestBody PageTemplate pageTemplate) {
        pageTemplate.setCreateTime(new Date());
        pageTemplate.setUpdateTime(pageTemplate.getCreateTime());
        pageTemplateService.save(pageTemplate);
        return MapResult.successResult().set("pageTemplateId", pageTemplate.getId());
    }

    @DeleteMapping("/{id}")
    public MapResult remove(@PathVariable("id") Long id) {
        pageTemplateService.remove(id);
        return MapResult.successResult();
    }
}
